package com.ssss.template.java8Template;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.func.Func;
import cn.hutool.json.JSONUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;

@Data
@Accessors(chain = true)
@AllArgsConstructor
public class Person {

    private Integer age;
    private String name;




    public static void main(String[] args) {
//        List<Person> list = new ArrayList<>();
//        Consumer<Person> consumer = x -> {
//            if (x.getName().equals("lisi")){
//                list.add(x);
//            }
//        };
//
//        Stream.of(
//                new Person(21,"zhangsan"),
//                new Person(22,"lisi"),
//                new Person(23,"wangwu")
//        ).forEach(consumer);
//
//        System.out.println(JSONUtil.toJsonStr(list));

        Consumer c = System.out::println;
//        Consumer c2 = n -> System.out.println(n+" -F2");
//        Consumer c3 = s -> System.out.println(s+"s3");
        // 执行完F后再执行F2的Accept方法
//        f.andThen(f2).accept("test");
//        c.andThen(c3).andThen(c2).accept("test");

        System.out.println("----------------------");
        Function<Integer,Integer> f = s -> s+1;
        Function<Integer,Integer> g = s -> s*2;

//        Integer apply = g.apply(1);
//        System.out.println("apply:"+apply);
        /**
         * 下面表示在执行f时，先执行g，并且执行f时 使用g的输出当做输入
         * 相当于以下代码
         * Integer a = g.apply(1);
         * System.out.println(f.apply(a));
         */
        System.out.println(f.compose(g).apply(1));

        /**
         * 先执行f的Apply后，然后再用f.apply()返回的结果作为值 ,去执行 g.apply()
         */
        System.out.println(f.andThen(g).apply(1));

        System.out.println("---------------------");

        Predicate<String> p = o -> o.equals("test");
        Predicate<String> q = o -> o.startsWith("t");

        boolean test = p.negate().test("test");
        System.out.println("test:"+test);

        boolean test1 = p.and(q).test("test");
        System.out.println("test1:"+test1);


    }
}

